home *** CD-ROM | disk | FTP | other *** search
/ Aminet 43 / Aminet 43 (2001)(GTI - Schatztruhe)[!][Jun 2001].iso / Aminet / comm / tcp / rxsocket.lha / rxsocket / examples / echotcp.rexx < prev    next >
OS/2 REXX Batch file  |  2001-03-01  |  1KB  |  48 lines

  1. /*
  2.     A very simple echo tcp client.
  3.     Show how to make a basic connection to a tcp service.
  4.     To test it on localhost, be sure echo/tcp is enabeld
  5.     in the services and inetd database, then write
  6.     rx echotcp localhost.
  7. */
  8.  
  9. l="rmh.library";if ~show("L",l) then;if ~addlib(l,0,-30) then exit
  10. if AddLibrary("rexxsupport.library","rxsocket.library")~=0 then exit
  11.  
  12. prg = ProgramName("NOEXT")
  13.  
  14. if ~RMH_ReadArgs("HOST/A") then do
  15.     call PrintFault()
  16.     exit
  17. end
  18.  
  19. addr = resolve(parm.0.value)
  20. if addr=="-1" then call err "no host <"parm.0.value">"
  21.  
  22. if ~getservbyname("SE","echo","tcp") then call err "echo tcp service not found"
  23.  
  24. sin.ADDRFAMILY = "INET"
  25. sin.ADDRADDR   = addr
  26. sin.ADDRPORT   = SE.SERVPORT
  27.  
  28. sock = socket("INET","STREAM","IP")
  29. if sock<0 then call err "no socket ("errno()")"
  30.  
  31. if connect(sock,"SIN")<0 then call err "connect error ("errno()")"
  32.  
  33. REQUEST = "echo service test"
  34. res = send(sock,REQUEST)
  35. if res~=length(REQUEST) then call err "send error ("errno()")"
  36.  
  37. len = recv(sock,"BUF",256)
  38. if len<0 then call err "recv error ("errno()")"
  39.  
  40. say buf
  41. call CloseSocket(sock)
  42. exit
  43.  
  44. err: procedure expose prg
  45. parse arg msg
  46.     say prg":" msg
  47.     exit
  48.